var prefix = jsctx + "/parking";

var addParkingSupplier = (function () {
    function init() {
        validateRule();
    };

    var isajaxsend = true;
    function save() {
        if (isajaxsend) {
            var formData = new FormData($("#frmParkingSupplier")[0]);
            $.ajax({
                cache: true,
                type: "POST",
                url: prefix + "/saveParkingSupplier",
                data: formData,
                processData: false,
                contentType: false,
                async: false,
                beforeSend: function () {
                    isajaxsend = false
                },
                error: function (request) {
                    parent.layer.alert("Connection error");
                },
                success: function (data) {
                    if (data.status == 200) {
                        parent.layer.msg("操作成功");
                        window.history.back();
                    } else {
                        parent.layer.alert(data.message)
                    }

                },
                complete: function () {
                    isajaxsend = false
                }
            });
        }
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#frmParkingSupplier").validate({
            rules: {
                supplierCode: {
                    required: true
                },
                supplierName: {
                    required: true
                }

            },
            messages: {
                supplierCode: {
                    required: icon + "请输入供应商编码"
                },
                supplierName: {
                    required: icon + "请输入供应商名称"
                }
            },
            submitHandler: function (form) {
                save();
            }
        })
    }
    return {
        init: init
    };
})();
